<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\api;
use app\models\GkyQyh;
use app\models\GkyQyhUser;
use app\common\utils\QyWechat;
/**
 * Description of ApprovalMessage
 *
 * @author yuilin
 */
class ApprovalMessage {
    public static function sendMessage($sender,$accepter,$type,$msgType,$printCode=""){
        $toUser = GkyQyhUser::findOne(['id'=>$accepter]);
        $fromUser=GkyQyhUser::findOne(['id'=>$sender]);
        $content='';
        if($type==0){
            $content=$fromUser->name."向您提交了".$msgType."的申请，请点击进入-->行政审批-->待我审批，进行处理";
        }else if($type==1){
            $content=$fromUser->name."已经同意了您".$msgType."的申请，请登录http://gky.fukangyun.com/index.php?r=print进行打印；打印码为：".$printCode;
        }else{
            $content="对不起，您".$msgType."的申请被拒绝！";
        }

        $message = [
            "touser" =>$toUser->userid,                //参数详情请访问http://qydev.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%E5%8F%8A%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F
            "safe"=> "0",			//是否为保密消息，对于news无效
            "agentid" => "1",	//应用id
            "msgtype" => "text",  //根据信息类型，选择下面对应的信息结构体
            "text"=>[
              "content"=>$content,  
            ],
        ];
        
        
        
         //获取当前企业号
        $weaccount = GkyQyh::findByCorpid(Constant::$GKY_CORPID);

        $options = array(
            'token'=>'gky',   //填写应用接口的Token
            'encodingaeskey'=>$weaccount->aeskey,//填写加密用的EncodingAESKey
            'appid'=>$weaccount->corpid,  //填写高级调用功能的appid
            'appsecret'=>$weaccount->secret, //填写高级调用功能的密钥
        );
        $weObj = new QyWechat($options);
        $weObj->sendMessage($message);
        
    }
}
